package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Banner;
import cn.wolfcode.luowowo.query.BannerQuery;
import cn.wolfcode.luowowo.query.TravelQuery;
import cn.wolfcode.luowowo.service.IBannerService;
import cn.wolfcode.luowowo.service.ITravelService;
import cn.wolfcode.luowowo.util.JsonResult;
import cn.wolfcode.luowowo.util.ParamMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IBannerService bannerService;

    @Autowired
    private ITravelService travelService;
    @GetMapping("/query")
    public Object query() {
        //游记推荐  前五
        List<Banner> banners = bannerService.query(Banner.TYPE_TRAVEL);
        //游记推荐  第一位
        Banner stBanner = bannerService.query(Banner.TYPE_STRATEGY).get(0);
        TravelQuery qo = new TravelQuery();
        //先设置为热门排序  因为首页第一位是热门排序
        qo.setOrderType(2);
        Page page = travelService.list(qo);
        return JsonResult.success(new ParamMap()
                .put("banners", banners)
                .put("stBanner", stBanner)
                .put("page", page)
        );
    }
}
